<script setup>
import { ref } from 'vue'
const todoName = ref('')

const emit = defineEmits(['addTodoFn'])
const add = () => {
  if (todoName.value) {
    emit('addTodoFn', todoName.value)
    todoName.value = ''
  }
}
</script>

<template>
  <header class="header">
    <h1>todos</h1>
    <input
      class="new-todo"
      placeholder="待办事项?"
      autofocus
      v-model="todoName"
      @keyup.enter="add"
    />
  </header>
</template>
